﻿namespace MicroCloud.Identity.Entities
{
    /// <summary>
    /// 组织机构信息基类
    /// </summary>
    /// <typeparam name="TKey">组织机构编号类型</typeparam>
    /// <typeparam name="TUserKey">用户编号类型</typeparam>
    public abstract class OrganizationBase<TKey, TUserKey> : EntityBase<TKey>, ILockable, ICreationAudited<TUserKey>, IUpdateAudited<TUserKey>, ISoftDeletable
        where TKey : struct, IEquatable<TKey>
        where TUserKey : struct, IEquatable<TUserKey>
    {
        #region "获取或设置 组织机构编码"
        private string _Code = "";
        /// <summary>
        /// 获取或设置 组织机构编码
        /// </summary>
        [Column("Code")]
        [Required, DefaultValue("")]
        [StringSize(StringSizeType.Code)]
        [DisplayName("组织机构编码")]
        public string Code { get { return _Code; } set { _Code = value.ReplaceNull(); } }
        #endregion

        /// <summary>
        /// 获取或设置 组织机构类型
        /// </summary>
        [Column("Type")]
        [DefaultValue(OrganizationType.Virtual)]
        [DisplayName("组织机构类型")]
        public OrganizationType Type { get; set; }

        #region "获取或设置 组织机构名称"
        private string _Name = "";
        /// <summary>
        /// 获取或设置 组织机构名称
        /// </summary>
        [Column("Name")]
        [Required, DefaultValue("")]
        [StringSize(StringSizeType.Name)]
        [DisplayName("组织机构名称")]
        public string Name { get { return _Name; } set { _Name = value.ReplaceNull(); } }
        #endregion

        #region "获取或设置 标准化名称"
        private string _NormalizedName = "";
        /// <summary>
        /// 获取或设置 标准化名称
        /// </summary>
        [Column("NormalizedName")]
        [Required, DefaultValue("")]
        [AuditIgnore]
        [StringSize(StringSizeType.Name)]
        [DisplayName("标准化名称")]
        public string NormalizedName { get { return _NormalizedName; } set { _NormalizedName = value.ReplaceNull(); } }
        #endregion

        #region "获取或设置 组织机构描述"
        private string _Description = "";
        /// <summary>
        /// 获取或设置 组织机构描述
        /// </summary>
        [Column("Description")]
        [StringSize(StringSizeType.Description)]
        [DisplayName("组织机构描述")]
        public string Description { get { return _Description; } set { _Description = value.ReplaceNull(); } }
        #endregion

        /// <summary>
        /// 获取或设置 顺序编号
        /// </summary>
        [Column("OrderNo")]
        [DisplayName("顺序编号")]
        public decimal OrderNo { get; set; }

        #region "获取或设置 节点树形路径"
        private string _TreePathString = "";
        /// <summary>
        /// 获取或设置 节点树形路径
        /// <para>树链Id根据一定格式构建的字符串，形如："$1$,$3$,$4$,$7$"，编辑时更新。</para>
        /// </summary>
        [Column("TreePathString")]
        [StringSize(StringSizeType.Description)]
        [DisplayName("节点树形路径")]
        public string TreePathString { get { return _TreePathString; } set { _TreePathString = value.ReplaceNull(); } }
        #endregion

        /// <summary>
        /// 获取或设置 父组织机构编号
        /// </summary>
        [Column("ParentId")]
        [DisplayName("父组织机构编号")]
        public TKey? ParentId { get; set; }

        /// <summary>
        /// 获取或设置 启用登陆
        /// </summary>
        [Column("EnableLogin")]
        [DefaultValue(false)]
        [DisplayName("启用登陆")]
        public bool EnableLogin { set; get; }

        /// <summary>
        /// 获取或设置 默认组织机构
        /// </summary>
        [Column("IsDefault")]
        [DisplayName("默认组织机构")]
        public bool IsDefault { get; set; }

        /// <summary>
        /// 获取或设置 是否系统组织机构
        /// </summary>
        [Column("IsSystem")]
        [DisplayName("是否系统组织机构")]
        public bool IsSystem { get; set; }

        /// <summary>
        /// 获取或设置 是否锁定当前信息
        /// </summary>
        [Column("IsLocked")]
        [DisplayName("是否锁定")]
        public bool IsLocked { get; set; }

        /// <summary>
        /// 获取或设置 创建者编号
        /// </summary>
        [Column("CreatorId")]
        [DisplayName("创建者编号")]
        public TUserKey? CreatorId { get; set; }

        /// <summary>
        /// 获取或设置 创建时间
        /// </summary>
        [Column("CreatedTime")]
        [DisplayName("创建时间")]
        public DateTime CreatedTime { get; set; }
    
        /// <summary>
        /// 获取或设置 更新者编号
        /// </summary>
        [DisplayName("更新者编号")]
        public TUserKey? UpdaterId { get; set; }
  
        /// <summary>
        /// 获取或设置 更新时间
        /// </summary>
        [DisplayName("更新时间")]
        public DateTime? UpdatedTime { get; set; }
        
        /// <summary>
        /// 获取或设置 数据逻辑删除时间
        /// （为 null 时表示为正常数据，有值表示已逻辑删除，同时删除时间每次不同也能保证索引唯一性）
        /// </summary>
        [Column("DeletedTime")]
        [DisplayName("删除时间")]
        public DateTime? DeletedTime { get; set; }

        #region 继承方法
        /// <summary>
        /// 输出字符串
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return Name;
        }

        #endregion

    }
}
